package ebj.common.base.print_chen;

//package PrintChen; 

import java.io.*;

//import java.lang.*; 

public class ChenOperator {
	public ChenOperator() {
		m_chars = new StringBuffer();
	}

	// 读取字符文件
	public boolean readTxtFile(String path) {
		if (null == path)
			return false;

		FileReader file_reader = null;
		try {
			file_reader = new FileReader(path);
		} catch (FileNotFoundException nfe) {
			System.out.println("Not Find the file: " + path
					+ "! Please Check the file whether exists.");
			return false;
		} catch (Exception e) {
			System.out.println("Unknown Exception.");
			return false;
		}

		readChars(file_reader);

		try {
			file_reader.close();
		} catch (IOException ioe) {
			System.out.println("Close file failed!");
			return false;
		}

		return true;
	}

	// 打印字符
	public void printChars(char c) {
		if (c != '#') {
			int length = m_chars.length();
			for (int i = 0; i < length; i++) {
				if ('#' == m_chars.charAt(i))
					m_chars.setCharAt(i, c);
			}
		}

		System.out.println(m_chars.toString());
	}

	// 获取字符窜
	public String getChars() {
		return m_chars.toString();
	}

	// --------------------------------------
	private void readChars(FileReader rd) {
		int ch = 0;
		try {
			while (-1 != (ch = rd.read())) {
				m_chars.append((char) ch);
			}
		} catch (IOException e) {
			System.out.println("IO Exception.");
			return;
		}
	}

	// 字符数据
	private StringBuffer m_chars;

}